

food.controller('AdminListConroller',function($scope,$http,page){
   
   $http({
    
    method:'get',
    url:'../Api/admin.php?action=admin_count'

   }).then(function(res){

     $scope.totalItems=res.data.c;

     console.log($scope.totalItems);

   });

   // 组装分页
   
 $scope.currentPage=1;
 $scope.bigTotalItems=8;
 $scope.maxSize=5;
 var url="../Api/admin.php?action=admin_list";
 page.getData(url,$scope.currentPage,$scope.bigTotalItems).then(function(res){
   $scope.admin_list=res;

   console.log($scope.admin_list);
 });

$scope.pageChanged=function(){
    page.getData(url,$scope.currentPage,$scope.bigTotalItems).then(function(res){
   $scope.admin_list=res;
 });

};






});


food.controller('AdminAddConroller',function($scope,$http,Upload,$location){



  // 图片上传的方法
  
 $scope.uploadImg = function()
    {
        if($scope.admin.admin_img){
            // 返回文件名称
            console.log($scope.admin.admin_img);
            // 进度条插件
            Upload.upload({
                url:"../Api/admin.php?action=admin_add",//返回图片路径 {'img':'404.jpg'}
                file:$scope.admin.admin_img
            }).success(function(result){
                $scope.admin.admin_img = "uploads/"+result.admin_img;//存到本地文件夹
            });
        }
    };

  // post数据提交的方法
  
  $scope.saveForm = function(){

        $http({
            method:"POST",
            url:"../Api/admin.php?action=admin_add",
            data:$scope.admin,

            headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
            transformRequest:function(obj){
                var str = [];
                for(var s in obj){
                    str.push(encodeURIComponent(s) + "=" + encodeURIComponent(obj[s]));
                }
                return str.join("&");
            }
        }).then(function(result){

            if(result.data){
                $location.path('admin_list');
            }else{
                alert('添加失败');
                $location.path('admin_list');
            }
        });
    }

 
});

food.controller('AdminEditeConroller',function($scope,$http,$stateParams,Upload,$location){
  
    // 查询出当前消息
   $http({
   	method:'get',
   	url:'../Api/admin.php?action=admin_detail&admin_id='+$stateParams.admin_id
   }).then(function(res){
       
    $scope.admin=res.data;
    
   });


   // 需要修改的信息
   
   

      // 图片上传的方法
  
 $scope.uploadImg = function()
    {
        if($scope.admin.admin_img){
            // 返回文件名称
            console.log($scope.admin.admin_img);
            // 进度条插件
            Upload.upload({
                url:"../Api/admin.php?action=admin_edite",//返回图片路径 {'img':'404.jpg'}
                file:$scope.admin.admin_img
            }).success(function(result){
                $scope.admin.admin_img = "uploads/"+result.admin_img;//存到本地文件夹
            });
        }
    };

  // post数据提交的方法
  
  $scope.saveForm = function(){

        $http({
            method:"POST",
            url:"../Api/admin.php?action=admin_edite&admin_id="+$stateParams.admin_id,
            data:$scope.admin,

            headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
            transformRequest:function(obj){
                var str = [];
                for(var s in obj){
                    str.push(encodeURIComponent(s) + "=" + encodeURIComponent(obj[s]));
                }
                return str.join("&");
            }
        }).then(function(result){

            if(result.data){
                $location.path('admin_list');
            }else{
                alert('添加失败');
                $location.path('admin_list');
            }
        });
    }
});

food.controller("AdminDeleteConroller",function($scope,$http,$stateParams,$location){

    $http({
        url:"../Api/admin.php?action=admin_delete&admin_id="+$stateParams.admin_id,
        method:"get"
    }).then(function(result){
        if(result.data)
        {
            $location.path('admin_list');
        }else{
            alert('删除失败');
            $location.path('admin_list');
        }
    });
});

food.controller('AdminActionConroller',function($scope,$http){

   $http({
   	method:'get',
   	url:'../Api/admin.php?action=admin_action'
   }).then(function(res){
        
        $scope.admin_action=res.data;
        console.log($scope.admin_action);

   });

});
